package com.hbu.product.hbumallproduct.controller;

import com.hbu.common.utils.R;
import com.hbu.product.hbumallproduct.entity.SkuInfoEntity;
import com.hbu.product.hbumallproduct.service.SkuInfoService;
import com.hbu.product.hbumallproduct.vo.SkuInfoListVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * sku??Ϣ
 *
 * @author zhaoxiaohan
 * @email 13315217827@163.com
 * @date 2022-10-27 22:52:07
 */
@RestController
@RequestMapping("hbumallproduct/skuinfo")
@AllArgsConstructor
public class SkuInfoController {

    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R list(SkuInfoListVO skuInfoList) {
        return R.ok().put("page", skuInfoService.getSkuList(skuInfoList));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId) {
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("skuInfo", skuInfo);
    }

    @RequestMapping(value = "/info/name/{skuId}", method = RequestMethod.GET)
    public String getNameById(@PathVariable Long skuId) {
        return skuInfoService.getNameById(skuId);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.save(skuInfo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.updateById(skuInfo);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds) {
        skuInfoService.removeByIds(Arrays.asList(skuIds));
        return R.ok();
    }

}
